// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import http from './components/util/http'
import store from './components/util/store'
import qs from 'qs'
import elementui from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import vuex from 'vuex'

Vue.use(vuex)
Vue.use(elementui)

Vue.config.productionTip = false
//设置vue属性
Vue.prototype.$http=http
Vue.prototype.$qs=qs
Vue.prototype.$store = store
/* eslint-disable no-new */

/* 路由守卫：前置守卫 beforeEach，跳转之前
          后置守卫 afterEach(),
          路径守卫:写在路由组件上 beforeEnter
          组件守卫:*/
// to:要跳转得新路由，form：当前路由

router.beforeEach((to, from, next) => {
  let loginUser = sessionStorage.getItem('token')
  if (to.name == 'Login' || loginUser != null) {
    // 去登录或者是已经登录
    next()
  } else {
    // 未登录
    next('/')
  }
})

router.beforeEach((to, form, next) => {
  let loginUser = sessionStorage.getItem('token')
  if (to.name == 'Login' || loginUser !=null) {
    // 去登录或者是已经登录
    next()
  } else {
    // 未登录
    next('/')
  }
})
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
